const { Router } = require('express')
const express = require('express')
//路由容器
const order = express.Router()
const axios = require('axios')
const { JsonWebTokenError } = require('jsonwebtoken')
const jwt = require("jsonwebtoken")
order.get('/order/haveNoOrderCount', (req, res) => {
    console.log(req.query)
    let {userId}=req.query
   axios({
       method:'get',
       url : '/order/haveNoOrderCount',
       headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token:req.session.token
        },
       params:{
        userId:jwt.decode(req.session.token).id
        }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
       console.log(err)
       res.status(500).json({
           msg:err
       })
   })
})
order.get('/order/haveOrderCount', (req, res) => {
    let {userId}=req.query
   axios({
       method:'get',
       url : '/order/haveOrderCount',
       headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token:req.session.token
    },
       params:{
        userId:jwt.decode(req.session.token).id
    }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
       res.status(500).json({
           msg:err
       })
   })
})
order.get('/order/queryAllOrderHave', (req, res) => {
    console.log(req.query)
    let {pageNo,pageSize,userId}=req.query
   axios({
       method:'get',
       url : '/order/queryAllOrderHave',
       headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token:req.session.token
    },
       params:{
        pageNo:pageNo,
        pageSize:pageSize,
        userId:jwt.decode(req.session.token).id
    }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
       res.status(500).json({
           msg:err
       })
   })
})
order.get('/order/queryAllOrderNo', (req, res) => {
    let {pageNo,pageSize}=req.query
    console.log(req.body)
    console.log(req.query)
   axios({
       method:'get',
       url : '/order/queryAllOrderNo',
       headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token:req.session.token
    },
       params:{
        pageNo:pageNo,
        pageSize:pageSize,
        userId:jwt.decode(req.session.token).id
    }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
        console.log(err)
        res.status(500).json({
           msg:err
       })
   })
})
order.put('/order/deleteOrderHave', (req, res) => {
    console.log(req.body.params)
    let {orderId}=req.body.params
    axios({
        method:'put',
        url : '/order/deleteOrderHave',
        params:{
            orderId:orderId
        }
    }).then(function(data){
        res.status(200).json({
            data:data.data,
            code:0
        })
    }).catch(function(err){
        res.status(500).json({
            msg:err
        })
    })
 })
 order.put('/order/deleteOrderNo', (req, res) => {
    console.log(req.body.params)
    let {orderId}=req.body.params
    axios({
        method:'put',
        url : '/order/deleteOrderNO',
        params:{
            orderId:orderId
        }
    }).then(function(data){
        res.status(200).json({
            data:data.data,
            code:0
        })
    }).catch(function(err){
        res.status(500).json({
            msg:err
        })
    })
 })
 order.put('/express/userSureOrNoSent', (req, res) => {
    console.log(req.body.params)
    let {orderId}=req.body.params
    axios({
        method:'put',
        url : '/express/userSureOrNoSent',
        params:{
            orderId:orderId
        }
    }).then(function(data){
        res.status(200).json({
            data:data.data,
            code:0
        })
    }).catch(function(err){
        res.status(500).json({
            msg:err
        })
    })
 })

module.exports=order;